package com.apes.pi.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 连接器参数
 *
 * @author wuq
 * @create 2019-10-19 10:44
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PiConnectorParams.CONST_TABLE_NAME)
public class PiConnectorParams extends BaseModel {
    public static final String CONST_TABLE_NAME = "pi_connector_params";

    @Id
    @ApesGenerator(code = CONST_TABLE_NAME, name = "PI连接器")
    @Column(name = "id", nullable = false, length = 8)
    @Comment("参数编码")
    private String id;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "connector_id", referencedColumnName="id")
    @Comment("连接器编码")
    private PiConnector connector;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type", referencedColumnName = "id")
    @Comment("参数类型")
    private Enumeration type; // 参数类型（content-type, appKey）

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category", referencedColumnName = "id")
    @Comment("参数类别")
    private Enumeration category;   // 参数类别（Params, headers, body,）

    @Column(name = "value", nullable = true, length = 2000)
    @Comment("值")
    private String value;   // 值
}
